package com.knight.study.patterns.tujie.builder;

/**
 * Builder定义了所有单点逻辑
 * TextBuilder中完成单点操作，
 * Director中完成合并后逻辑
 * 局限性：只适合能有Builder的不同类
 * @Author knight
 * @Date 2024/9/10 17:11
 */

public class BuilderMain {

    public static void main(String[] args) {
        System.out.println(args.length);
        if (args.length != 1) {
            usage();
            System.exit(0);
        }

        if (args[0].equals("plain")) {
            final TextBuilder textBuilder = new TextBuilder();
            final Director director = new Director(textBuilder);
            director.construct();
            final String result = textBuilder.getResult();
            System.out.println(result);
        } else if (args[0].equals("html")) {
            final HTMLBuilder htmlBuilder = new HTMLBuilder();
            final Director director = new Director(htmlBuilder);
            director.construct();
            final String result = htmlBuilder.getResult();
            System.out.println(result + "文件编写完成。");
        } else {
            usage();
            System.exit(0);
        }
    }

    public static void usage() {
        System.out.println("Usage: java main plain 文档。");
        System.out.println("Usage: java main plain HTML。");
    }
}
